package com.lanou3g.hw0419.question2;

import java.io.*;
import java.util.Random;

/**
 * Created by dllo on 18/4/19.
 */
public class Main {
    //目标1
    public static final long TARGET = 1024L * 1024 * 1024;

    public static void main(String[] args) {
        new Thread(){
            @Override
            public void run() {
                creatFile("a","/Users/dllo/Desktop/19号作业/Q2");
            }
        }.start();

        creatFile("b","/Users/dllo/Desktop/19号作业/Q2");
    }

    private static void creatFile(String filename, String filePath) {
        File file = new File(filePath, filename);
        BufferedOutputStream bos = null;
        try {
            bos = new BufferedOutputStream(new FileOutputStream(file));
            Random random=new Random();
            byte[] buf = new byte[1024];
            random.nextBytes(buf);
            long sum = 0;
            while (sum < TARGET) {
                bos.write(buf);
                sum += 1024L;
            }
            bos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (bos!=null){
                try {
                    bos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
